package com.jeegit.ecms.service.impl;

import java.util.List;
import com.jeegit.common.utils.DateUtils;
import com.jeegit.common.utils.IdUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jeegit.ecms.mapper.CmsVideoDataMapper;
import com.jeegit.ecms.mapper.CmsVideoMapper;
import com.jeegit.ecms.domain.CmsVideo;
import com.jeegit.ecms.service.ICmsVideoService;
import com.jeegit.common.core.text.Convert;

/**
 * 录播课程Service业务层处理
 * 
 * @author jeegit
 * @date 2022-06-30
 */
@Service
public class CmsVideoServiceImpl implements ICmsVideoService 
{
    @Autowired
    private CmsVideoMapper cmsVideoMapper;
    
    @Autowired
    private CmsVideoDataMapper cmsVideoDataMapper;

    /**
     * 查询录播课程
     * 
     * @param id 录播课程主键
     * @return 录播课程
     */
    @Override
    public CmsVideo selectCmsVideoById(Long id)
    {
	CmsVideo cmsVideo= cmsVideoMapper.selectCmsVideoById(id);
	if (cmsVideo != null && cmsVideo.getId()>0l) {
	    cmsVideo.setCmsVideoData((cmsVideoDataMapper.selectCmsVideoDataById(id)));
	}
        return cmsVideo;
    }

    /**
     * 查询录播课程列表
     * 
     * @param cmsVideo 录播课程
     * @return 录播课程
     */
    @Override
    public List<CmsVideo> selectCmsVideoList(CmsVideo cmsVideo)
    {
        return cmsVideoMapper.selectCmsVideoList(cmsVideo);
    }

    /**
     * 新增录播课程
     * 
     * @param cmsVideo 录播课程
     * @return 结果
     */
    @Override
    public int insertCmsVideo(CmsVideo cmsVideo)
    {
    	cmsVideo.setId(IdUtils.getInstance(1l).nextId());
    	cmsVideo.preInsert(cmsVideo);
    	cmsVideo.getCmsVideoData().setId(cmsVideo.getId());
    	cmsVideo.getCmsVideoData().preInsert(cmsVideo.getCmsVideoData());;
    	int resultCount=cmsVideoMapper.insertCmsVideo(cmsVideo);
    	cmsVideoDataMapper.insertCmsVideoData(cmsVideo.getCmsVideoData());
        return resultCount;
    }

    /**
     * 修改录播课程
     * 
     * @param cmsVideo 录播课程
     * @return 结果
     */
    @Override
    public int updateCmsVideo(CmsVideo cmsVideo)
    {
    	cmsVideo.preUpdate(cmsVideo);
    	cmsVideo.getCmsVideoData().preUpdate(cmsVideo.getCmsVideoData());
    	cmsVideo.getCmsVideoData().setId(cmsVideo.getId());
    	int resultCount=cmsVideoMapper.updateCmsVideo(cmsVideo);
    	cmsVideoDataMapper.updateCmsVideoData((cmsVideo.getCmsVideoData()));
        return resultCount;
         
    }

    /**
     * 批量删除录播课程
     * 
     * @param ids 需要删除的录播课程主键
     * @return 结果
     */
    @Override
    public int deleteCmsVideoByIds(String ids)
    {
        return cmsVideoMapper.deleteCmsVideoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除录播课程信息
     * 
     * @param id 录播课程主键
     * @return 结果
     */
    @Override
    public int deleteCmsVideoById(Long id)
    {
        return cmsVideoMapper.deleteCmsVideoById(id);
    }
}
